﻿
Public Class frmError_Sumary
    Dim strsql As String
    Dim mysql As New ClsSQLhelper
    Dim On_Load As Boolean = True
#Region "Function"
    Sub Load_Summary(ByVal OPPPTable As String, ByVal UploadFile As Integer, Optional ByVal ShowCompleteMsg As Boolean = True)
        Try
            strsql = "select CODE_ID,Count(CODE_ID) as Totalrows from " & OPPPTable & " where filename = " & UploadFile & " and code_id is not null  group by code_id "
            Dim DT_Service As New DataTable
            DT_Service = mysql.GetMYSQLDataTable(strsql, "ERROR_Summary")
            With DataGridView1
                .RowHeadersVisible = False
                .AllowDrop = False
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .AllowUserToOrderColumns = True
                .AllowUserToResizeColumns = True
                .AllowUserToResizeRows = False
                .MultiSelect = False
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
                .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
                .DataSource = DT_Service 'DSOPPP.Tables("m_person")
                If ShowCompleteMsg = True Then
                    MsgBox("ดึงข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
                End If

            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub Load_FolderName(ByVal FileName As Integer)
        Try
            Dim FileType As String
            strsql = "Select TYPE_DESC from m_files_upload where ROWID = " & FileName
            FileType = mysql.MySQLExecuteScalar(strsql)
            With CboFolder
                .Items.Clear()
                Select Case FileType
                    Case "OP Package"
                        .Items.Add("PERSON")
                        .Items.Add("SERVICE")
                        .Items.Add("DIAG")
                        .Items.Add("PROCED")
                        .Items.Add("DRUG")
                    Case "PP Package"
                        .Items.Add("PERSON")
                        .Items.Add("EPI")
                        .Items.Add("ANC")
                        .Items.Add("FP")
                        .Items.Add("MCH")
                        .Items.Add("PP")
                    Case "18 แฟ้ม"
                        .Items.Add("PERSON")
                        .Items.Add("SERVICE")
                        .Items.Add("DIAG")
                        .Items.Add("PROCED")
                        .Items.Add("DRUG")
                        .Items.Add("EPI")
                        .Items.Add("ANC")
                        .Items.Add("FP")
                        .Items.Add("MCH")
                        .Items.Add("PP")

                End Select
                .Text = "PERSON"
            End With

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
#End Region
    Private Sub frmError_Sumary_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim DT_m_files_upload As New DataTable
            With Me.CboImportOPFile
                strsql = "select ROWID,FILENAME from m_files_upload "
                strsql = strsql & " order by Date_SEND DESC"

                DT_m_files_upload = mysql.GetMYSQLDataTable(strsql, "m_files_upload")
                If DT_m_files_upload.Rows.Count = 0 Then
                    MsgBox("คุณต้องนำข้อมูลเข้าโปรแกรมตรวจสอบ NHSO OPPP 2554 ก่อน", MsgBoxStyle.Exclamation)
                    Exit Sub
                End If
                .DataSource = DT_m_files_upload
                .DisplayMember = "FILENAME"
                .ValueMember = "ROWID"
                .SelectionStart = 0
                Me.CboImportOPFile.SelectionStart = DT_m_files_upload.Rows(0).Item("ROWID").ToString
                Load_FolderName(DT_m_files_upload.Rows(0).Item(0))
                Me.On_Load = False
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub

    Private Sub CboImportOPFile_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboImportOPFile.SelectedIndexChanged
        If On_Load = True Then Exit Sub
        Try
            Load_FolderName(Me.CboImportOPFile.SelectedValue)
            ' Load_Summary("m_" & Me.CboFolder.Text, Me.CboImportOPFile.SelectedValue)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
        Load_Summary("m_" & Me.CboFolder.Text, Me.CboImportOPFile.SelectedValue)

    End Sub

    Private Sub CboFolder_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboFolder.SelectedIndexChanged
        If On_Load = True Then Exit Sub
        Load_Summary("m_" & Me.CboFolder.Text, Me.CboImportOPFile.SelectedValue)
    End Sub
End Class